import requests


# from urllib.request import urlopen

# url='https://www.baidu.com/';
# con=urlopen(url);
# cons=con.read();
# f=open('下载的网页','wb');
# f.write(cons);
# f.close();
# print(cons.decode('utf-8'));

# url='https://www.baidu.com/';
# par={
#     "wd":'你好'
# }
# result=requests.get(url,params=par)
# print(result.text);
# print(result.url);


def postTest(text):
    print(text);
    search = input('请输入想要翻译得到单词');
    url = 'https://fanyi.baidu.com/sug';
    par = {"kw": search}
    data = requests.post(url, data=par).json();
    print(data);
    print(data['errno']);


def fyq(name):
    print(name);
    search = input('请输入想要翻译得到单词');
    data = requests.post('https://fanyi.baidu.com/sug', data={"kw": search}).json()['data'];
    for i in range(len(data)):
        print(f"{data[i]['k']}---->{data[i]['v']}");


if __name__ == "__main__":
    # postTest('测试post');
    fyq('翻译器');
